EPUB=/tmp/epub/epub.htm
if [[ -z "$1" ]] ; then
echo "Usage: ./epub.sh book.epub"
exit
fi
rm -rf /tmp/epub
mkdir -p /tmp/epub
unzip "$1" -d /tmp/epub
cd /tmp/epub/
find /tmp/epub/ -exec detox {} \;
find /tmp/epub/ -type f \( -iname "*.htm*" -or -iname "*.xml" -or -iname  "*.xhtml" \) |  sort > /tmp/epub/tofind
cat /tmp/epub/tofind
for i in $(cat /tmp/epub/tofind) 
do
cat "$i" >> /tmp/epub/epub.htm
done
if [ -d /tmp/epub/OEBPS/ ] ; then
cp -r  /tmp/epub/epub.htm  /tmp/epub/OEBPS/epub.htm
EPUB=/tmp/epub/OEBPS/epub.htm
fi
links -g   $EPUB
rm -rf /tmp/epub/
